/*
 * @Description: 路由
 * @Author: xinqiao lxq1990.0716@qq.com
 * @Date: 2024-05-07
 * @LastEditors: xinqiao lxq1990.0716@qq.com
 * @LastEditTime: 2025-02-12
 */
import type { App } from 'vue'
import type { RouteRecordRaw } from 'vue-router'
import { createRouter, createWebHistory } from 'vue-router'

import { checkWhiteRoute, createRouterGuards, goLogin } from './guard'
import { getSubModuleRoute, moduleRoutes, subModuleMap, sysModuleRoutes } from './routes'

export const routes: RouteRecordRaw[] = [...sysModuleRoutes, ...moduleRoutes]

export const router = createRouter({
  history: createWebHistory(import.meta.env.VITE_BASE_ROUTE_PATH),
  routes,
})

export const setupRouter = async (app: App) => {
  createRouterGuards(router)
  app.use(router)
  // 路由准备就绪后挂载APP实例
  await router.isReady()
}

export { checkWhiteRoute, getSubModuleRoute, goLogin, subModuleMap }

export default router
